package pers.chao.tool.image;

import org.springframework.util.StringUtils;

import java.util.Arrays;

/**
 * Description: 图片扩展名
 *
 * @author W.Chao
 * @date 2020/11/15 11:39
 **/
public enum ImageSuffix {
	GIF("gif"),
	JPG("jpg"),
	JPEG("jpeg"),
	BMP("bmp"),
	PNG("png"),
	PSD("psd"),
	EPS("eps"),
	SVG("svg"),
	PDF("pdf");

	private String name;

	ImageSuffix(String name) {
		this.name = name;
	}

	public String lower() {
		return name.toLowerCase();
	}

	public String upper() {
		return name.toUpperCase();
	}

	public static boolean in(String suffix) {
		if (StringUtils.isEmpty(suffix)) {
			return false;
		}
		return Arrays.stream(ImageSuffix.values())
				.map(imageSuffix -> imageSuffix.name)
				.anyMatch(imageSuffix -> imageSuffix.equalsIgnoreCase(suffix));
	}
}
